package com.kantboot.user.account.web.controller;

import com.alibaba.fastjson2.JSON;
import com.kantboot.user.account.domain.entity.UserTest;
import com.kantboot.user.account.repostiroy.UserTestRepository;
import com.kantboot.util.common.result.RestResult;
import jakarta.annotation.Resource;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private UserTestRepository userTestRepository;

    @PersistenceContext
    private EntityManager entityManager;


    @Transactional
    @Modifying
    @RequestMapping("/test")
    public RestResult test() {
        // 开始时间
        long start = System.currentTimeMillis();
        System.err.println(start);
        List<UserTest> list = new ArrayList<>();
        for (int i = 0; i < 5000; i++) {
            UserTest userTest = new UserTest()
                    .setUsername("username" + i+"----------------------------")
                    .setEmail("email" + i+"----------------------------"+i)
                    .setPassword("password" + i+"----------------------------"+i);
            System.err.println(JSON.toJSONString(userTest));
        }
        // 结束时间
        long end = System.currentTimeMillis();
        System.err.println("耗时：" + (end - start)+ "毫秒");
        return RestResult.success("耗时：" + (end - start) + "毫秒", "success", "成功");
    }

}
